package priv.pront.code.national.acwing.dp.bags;

import java.util.Scanner;

public class A3_完全背包问题 {

    static int N, V;
    static int[][] dp;
    static int[] w, v;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        V = scanner.nextInt();
        w = new int[N + 1];
        v = new int[N + 1];
        dp = new int[N + 1][V + 1];
        for (int i = 1; i <= N; i++) {
            v[i] = scanner.nextInt();
            w[i] = scanner.nextInt();
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= V; j++) {
                for (int k = 0; k * v[i] <= j; k++) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - k * v[i]] + w[i] * k);
                }
            }
        }

        System.out.println(dp[N][V]);

//        维度优化

//        Scanner scanner = new Scanner(System.in);
//        N = scanner.nextInt();
//        V = scanner.nextInt();
//        w = new int[N + 1];
//        v = new int[N + 1];
//        dp = new int[N + 1][V + 1];
//        for (int i = 1; i <= N; i++) {
//            v[i] = scanner.nextInt();
//            w[i] = scanner.nextInt();
//        }
//        for (int i = 1; i <= N; i++) {
//            for (int j = 1; j <= V; j++) {
//                dp[i][j] = dp[i - 1][j];
//                if(j >= v[i]) dp[i][j] = Math.max(dp[i][j], dp[i][j - v[i]] + w[i]);
//            }
//        }
//
//        System.out.println(dp[N][V]);
//    }


//        维度优化 + 空间优化

//        Scanner scanner = new Scanner(System.in);
//        N = scanner.nextInt();
//        V = scanner.nextInt();
//        w = new int[N + 1];
//        v = new int[N + 1];
//        dp = new int[V + 1];
//        for (int i = 1; i <= N; i++) {
//            v[i] = scanner.nextInt();
//            w[i] = scanner.nextInt();
//        }
//        for (int i = 1; i <= N; i++) {
//            for (int j = v[i]; j <= V; j++) {
//                dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
//            }
//        }
//
//        System.out.println(dp[V]);

    }
}
